package com.wxy.xr.dao.impl;

import com.wxy.xr.bean.Education;

import com.wxy.xr.dao.EducationDao;
import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.util.ArrayList;
import java.util.List;

public class EducationDaoImpl extends BaseDaoImpl<Education> implements EducationDao {


    /**
     * 添加或更新
     * @param website
     * @return
     */
    public boolean save(Education bean){
        Integer id=bean.getId();
        List<Object> args = new ArrayList<>();
        args.add(bean.getName());
        args.add(bean.getType());
        args.add(bean.getIntro());
        args.add(bean.getBeginDay());
        args.add(bean.getEndDay());
        String sql;
        if(id==null || id<1){
            sql="INSERT INTO education(name,type,intro,begin_day,end_day) values(?,?,?,?,?)";
        } else {
            sql="UPDATE education set name=? ,type=?, intro=?, begin_day=? ,end_day=? where id =?";
            args.add(id);
        }
        return tpl.update(sql,args.toArray())>0;
    }

    /**
     *获取单个对象
     * @param id
     * @return
     */
    public Education get(Integer id){
        String sql="select id, created_time, name,type,intro,begin_day,end_day from education where id=?";
        return tpl.queryForObject(sql,new BeanPropertyRowMapper<>(Education.class),id);
    }

    /**
     * 获取多个对象
     * @return
     */
    public List<Education> list(){
        String sql="select id, created_time, name,type,intro,begin_day,end_day from education";
        return tpl.query(sql, new BeanPropertyRowMapper<>(Education.class));
    }


}
